<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html>
<html>
<head>
    <title>用户管理</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/lib/weui.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/css/jquery-weui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/css/main.css">

</head>

<body ontouchstart>


<header class='demos-header'>
    <h1 class="demos-title">人员管理</h1>
</header>

<div class="bd">
    <div class="page__bd">
        <div class="weui-cells">

            <c:forEach items="${users}" var="user">
                <div class="weui-cell weui-cell_swiped weui-cell-swipe-user" value="${user.id}" id="swipe1">
                    <div class="weui-cell__bd">
                        <div class="weui-cell">
                            <div class="weui-cell__bd">
                                <p>【${user.role}】${user.name}</p>
                            </div>
                            <div class="weui-cell__ft">${user.phone}></div>
                        </div>
                    </div>
                    <div class="weui-cell__ft">
                        <a class="weui-swiped-btn edit-swipeout" style="background-color: #0BB20C" uid="${user.id}"   href="javascript:">编辑</a>
                        <a class="weui-swiped-btn weui-swiped-btn_warn delete-swipeout"  uid="${user.id}" href="javascript:">删除</a>
                    </div>
                </div>
            </c:forEach>
        </div>
        <div class="button_sp_area" style="text-align: center;">
            <a href="javascript:;" class="weui-btn weui-btn_primary" id="add">添加用户</a>
        </div>
    </div>
</div>
<div class="weui-tabbar">
    <a href="${pageContext.request.contextPath}/index.do" class="weui-tabbar__item weui-bar__item">
        <div class="weui-tabbar__icon">
            <img src="${pageContext.request.contextPath}/static/weui/images/index.png" alt="">
        </div>
        <p class="weui-tabbar__label">返回首页</p>
    </a>
</div>
<script src="${pageContext.request.contextPath}/static/weui/lib/jquery-2.1.4.js"></script>
<script src="${pageContext.request.contextPath}/static/weui/lib/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="${pageContext.request.contextPath}/static/weui/js/jquery-weui.js"></script>


<script>
    $("#add").click(function () {
        window.location.href = "${pageContext.request.contextPath}/user/editUser.do?action=add";
    });

    $('.weui-cell').click(function () {
        $(this).swipeout('open');
    });

    $('.delete-swipeout').click(function () {
        let uid=$(this).attr("uid");
        $.confirm("您确定要删除吗?", "确认删除?", function () {
            $.ajax({
                url: '${pageContext.request.contextPath}/user/delUser.do',
                data: {uid:uid},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.code == '200') {
                        $.alert("删除成功！", "成功");
                        $(this).parents('.weui-cell').remove();
                    } else {
                        $.alert("删除失败！", "失败");
                    }
                }
            });
        }, function () {
            //取消操作
        });
    });

    $('.edit-swipeout').click(function () {
        let uid=$(this).attr("uid");
        window.location.href = "${pageContext.request.contextPath}/user/editUser.do?action=edit&id=" + uid;
    });


    $('.close-swipeout').click(function () {
        $(this).parents('.weui-cell').swipeout('close');
    });
</script>
</body>
</html>
